﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using MisDLL;
using System.Data;

namespace MisBLL
{
    public class JhTypeDAO : MarshalByRefObject, IJhType
    {
        protected DbHelper dbHelper = new DbHelper();

        //根据编码查询供应商类型信息
        public MisModel.JHType GetById(string jhId)
        {
            if (string.IsNullOrEmpty(jhId))
                return null;
            string sql = string.Format("select * from JHTYPE_TAB where JH_ID='{0}'", jhId);
            DataTable dt=  dbHelper.ExecuteDataTable(sql);
            MisModel.JHType entity = null;
            if (dt != null && dt.Rows.Count > 0){
                entity = new MisModel.JHType();
                entity.JhID = dt.Rows[0]["JH_ID"].ToString();
                entity.JhType = dt.Rows[0]["JHType"].ToString();
                entity.F1 = dt.Rows[0]["F1"].ToString();
            }
            return entity;
        }

        //查询供应商类型列表
        public DataTable GetAll()
        {
            string sql = "select JH_ID,JHType,F1,(JH_ID + '.' + JHType) as ItemShow  from JHTYPE_TAB";
            return dbHelper.ExecuteDataTable(sql);
        }

        //添加供应商类型信息
        public int Add(MisModel.JHType obj)
        {
            if (string.IsNullOrEmpty(obj.F1.ToString()))
            {
                obj.F1 = "Y";
            }
            string sql = string.Format("insert into JHTYPE_TAB(JH_ID,JHType,F1) values('{0}','{1}','{2}')", obj.JhID, obj.JhType, obj.F1);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //修改供应商类型信息
        public int Update(MisModel.JHType obj)
        {
            string sql = string.Format("update JHTYPE_TAB set JHType='{0}',F1='{1}' where JH_ID='{2}'", obj.JhType, obj.F1, obj.JhID);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //根据ID删除供应商类型信息
        public int Delete(string id)
        {
            string sql = string.Format("delete from JHTYPE_TAB where JH_ID='{0}'", id);
            return dbHelper.ExecuteNonQuery(sql);
        }
    }
}
